<template>
	<view class="invitation">
		<view class="invitation_content">
			{{recruitId ? `您好，[你的朋友${nickName}]邀请您成为他的专属代招合伙人` :
			'您好，很高兴您成为我们的代招合伙人'}}
		</view>
		<view class="bottom">
			<u-button type="primary" :custom-style="customStyle" @click="submit">同意</u-button>
			<u-button type="info" :custom-style="customStyle" @click="close">考虑一下</u-button>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				shareNum : 3,
				customStyle: {
					marginBottom: '20px', // 注意驼峰命名，并且值必须用引号包括，因为这是对象
				},
				recruitId: '',
				nickName: ''
			}
		},
		onLoad(e = {}) {
			console.log(e)
			this.recruitId = e.id;
			if(e.recId) {
				this.recruitId = e.recId
				this.nickName = e.name
			}
		},
		methods:{
			submit() {
				if(!uni.getStorageSync('token')) {
					uni.showModal({
						title: '提示',
						content: '您需要登录才可以执行后续操作!',
						success: (e) => {
							e.confirm && uni.navigateTo({
								url: '/pages/login'
							})
						}
					})
					return
				}
				this.$u.api.applySmall({recId: this.recruitId}).then(res => {
					if (res.status == true) {
						uni.showToast({
							title: '申请成功！',
							duration: 2000
						});
						
						setTimeout(() => {
							if(this.recruitId) {
								uni.reLaunch({
									url: '/pages/share/apply'
								})
							} else {
								uni.reLaunch({
									url: '/pages/index/home'
								})
							}
							
						}, 2000)
					} else {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						});
					} 
				})
			},
			close() {
				uni.redirectTo({
					url: '/pages/index/full-screen?recId=' + this.recruitId
				})
			}
		}
	}
</script>
<style>
   page{ background:#FFFFFF }
</style>
<style lang="scss" scoped>
	.invitation_content{
		padding: 300upx 100upx 0upx;
		height: 810upx;
		font-size: 50upx;
	}
	.bottom{
		margin: 0 auto;
		width: 600upx;
	}
</style>
